import React, { useState, useEffect, memo } from 'react'

import { navs } from 'config/navs'

import { getBanners, getHomeGroups, getHomeNews } from 'services/home'


import Swiper from 'components/Swiper'
import Navs from 'components/Navs'


import HomeGroups from '../c-cpns/HomeGroups'
import HomeNews from '../c-cpns/HomeNews'

export default memo(function Index() {
  const [banners, setBanners] = useState([])
  const [homeGroups, setHomeGroups] = useState([])
  const [homeNews, setHomeNews] = useState([])

  useEffect(() => {
    _getBanners()
    _getHomeGroups('AREA%7C88cff55c-aaa4-e2e0')
    _getHomeNews('AREA%7C88cff55c-aaa4-e2e0')
  }, [])

  /**
   * 网络请求
   */
  const _getBanners = async () => {
    const result = await getBanners()
    setBanners(result.body)
  }

  const _getHomeGroups = async (areaId) => {
    const result = await getHomeGroups(areaId)
    setHomeGroups(result.body)
  }

  const _getHomeNews = async (areaId) => {
    const result = await getHomeNews(areaId)
    setHomeNews(result.body)
  }

  /**
   * 事件监听
   */

   const currentCity = new window.BMapGL.LocalCity();
   currentCity.get((res) => {
     
     console.log(res)
   })

  // console.log(window.BMap)

  return (
    <>
      <Swiper info={banners} />
      <Navs navs={navs} />
      <HomeGroups groupInfo={homeGroups} />
      <HomeNews homeNews={homeNews} />

    </>

  )
})

